package com.su.ou.yang;

import com.sun.tools.javac.util.Position;

public class Test5 {
    public static void main(String[] args) {
    char[][] hill={
        {'1','1','0','0','0'},
        {'1','1','0','0','0'},
        {'0','0','1','0','0'},
        {'0','0','0','1','1'}
        };
        System.out.println(solve(hill));

    }
    public static  int solve(char[][] hill){
        int n = hill.length;
        int m=hill[0].length;
        if(hill==null||n==0){
            return 0;
        }
        int count=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
               if(hill[i][j]=='1'){
                   count++;
                   dfs(hill, i,j );
               }
            }
        }
        return count;
    }

    private static void dfs(char[][] hill, int i, int j) {
        if(i>=hill.length||i<0||j>=hill[i].length||j<0||hill[i][j]!='1'){
            return;
        }

        hill[i][j]='0';
        dfs(hill,i+1,j);
        dfs(hill, i-1, j);
        dfs(hill, i, j-1);
        dfs(hill, i, j+1);

    }

}
